//上传学生图片预览
function previewFile() {
    var preview = document.querySelector(".image img");
    var file  = document.querySelector('input[type=file]').files[0];
    var reader = new FileReader();
    reader.onload  = function () {
        preview.src = reader.result;
    }
    if (file) {
        reader.readAsDataURL(file);
    } else {
        preview.src = "";
    }
}

$(document).ready(function () {
    //给sex设置默认值
    $("#student_sex").val($("#student_sex").attr("about"));
    //给state设置默认值
    $("#student_state").val($("#student_state").attr("about"));
    //给duty设置默认值
    $("#student_duty").val($("#student_duty").attr("about"));
    //得到宿舍列表
    $.get("/StudentServlet?action=getDormitory_id",function (data) {
        $(data).find("dormitory_id").each(function () {
            var dormitory_id=$(this).text();
            $("#student_dormitory_id").append("<option value="+dormitory_id+">"+dormitory_id+"</option>");
            //给宿舍设置默认值
            $("#student_dormitory_id").val($("#student_dormitory_id").attr("about"));

        });
    });
    //得到所有班级列表
    $.get("/ClassServlet?action=getClassList",function (data) {
        $(data).find("class_id").each(function () {
           var class_id=$(this).text();
            $("#student_class_id").append("<option value="+class_id+">"+class_id+"</option>");
            //给class_id设置默认值
            $("#student_class_id").val($("#student_class_id").attr("about"));
        });
    });



    //获取提交后的提示
    if($("#message").val()!=""){
        alert($("#message").val());
    }
});